package com.ws.shop.action.front;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.ws.shop.entity.Article;
import com.ws.shop.entity.Auction;
import com.ws.shop.entity.Sunpic;
import com.ws.shop.service.ArticleService;
import com.ws.shop.service.AuctionService;
import com.ws.shop.service.SunpicService;
import com.ws.shop.service.impl.AuctionCacheImpl;



@Controller
@RequestMapping(value="/*")//请求目录
public class IndexAction extends BaseFrontAction{

	private static Logger log = Logger.getLogger(IndexAction.class);
	@Autowired
	private AuctionService auctionService;
	@Autowired
	private ArticleService articleService;
	@Autowired
	private SunpicService sunpicService;
	
	
	@RequestMapping(value="index.htm",method=RequestMethod.GET)//请求地址
	public String index(HttpServletRequest request,Model model){
		try {
			log.info("+++++++获取正在热拍++");
			List<Map<String,Object>> auctioning = auctionService.findeAuctionList(1,20); 
//			List<Auction> auctioning = AuctionCacheImpl.auctionlist;
			log.info("+++++++获取最新成交的 或者说结束的++++++");
			List<Map<String,Object>> auctioned = auctionService.findeAuctionList(2,6); 
//			List<Auction> auctioned = AuctionCacheImpl.auctedlist;
			//公告分类1
			List<Map<String,Object>> news = articleService.getArticle(1, 100001, 6);
//			List<Article> news = AuctionCacheImpl.articlelist;
			//获取最新4条晒图
//			log.info("++++获取最新6条晒图+++++");
//			List<Object> sunpics = sunpicService.sunpics(1, 4);
//			List<Sunpic> sunpics = AuctionCacheImpl.sunpiclist;
			model.addAttribute("auctioning", auctioning);
			model.addAttribute("news", news);
//			model.addAttribute("sunpics", sunpics);
			model.addAttribute("auctioned", auctioned);
		} catch (Exception e) {
			e.printStackTrace();
			log.error("显示首页出错",e);
		}
		return "index";
	}
}
